C     PROGRAM SAMDAT(INPUT,OUTPUT,TAPE5=INPUT,TAPE6=OUTPUT)

C*******************************************************************************
C
C
C
C     EXECUTIVE PROGRAM FOR SAMPLED-DATA REGULATOR PROBLEM
C
C
C
C*******************************************************************************
      IMPLICIT REAL*8 (A-H,O-Z)
      DIMENSION A(16),B(8),Q(16),R(4),ATIL(16),BTIL(8),QTIL(16),WTIL(8),
     1RTIL(4),FTIL(8),AHAT(16),QHAT(16),FHAT(8),DUMMY(116),P(16),F(8)
      DIMENSION NA(2),NB(2),NQ(2),NR(2),NATIL(2),NBTIL(2),NQTIL(2),NWTIL
     1(2),NRTIL(2),NFTIL(2),NAHAT(2),NQHAT(2),NFHAT(2),IOP(5),NP(2),NF(2
     2),NDUM(2)
      LOGICAL IDENT,DISC,NEWT,STABLE,FNULL
C
C     INPUT HOLLERITH DATA FOR TITLE OF OUTPUT
      CALL RDTITL
C
C     INPUT COEFFICIENT AND WEIGHTING MATRICES FOR CONTINUOUS SYSTEM
      CALL READ(4,A,NA,B,NB,Q,NQ,R,NR)
C
C     GENERATE EXP (A*DELT) AND (INTEGRAL EXP(A*TAU))*B
      DELT=.05
      IOP(1)=0
      N1 = (NA(1)**2)+1
C
      CALL EXPINT(A,NA,ATIL,NATIL,DUMMY,NDUM,DELT,IOP,DUMMY(N1))
      CALL MULT(DUMMY,NDUM,B,NB,BTIL,NBTIL)
      CALL PRNT(ATIL,NATIL,4HATIL,1)
      CALL PRNT(BTIL,NBTIL,4HBTIL,1)
C
C     GENERATE DIGITAL PERFORMANCE INDEX WEIGHTING MATRICES
      IOP(2)=1
      CALL EQUATE(Q,NQ,QTIL,NQTIL)
      CALL EQUATE(R,NR,RTIL,NRTIL)
      CALL SAMPL(A,NA,B,NB,QTIL,NQTIL,RTIL,NRTIL,WTIL,NWTIL,DELT,IOP,DUM
     1MY)
      CALL PRNT(QTIL,NQTIL,4HQTIL,1)
      CALL PRNT(WTIL,NWTIL,4HWTIL,1)
      CALL PRNT(RTIL,NRTIL,4HRTIL,1)
C
C     FIND PREFILTER GAIN WHICH ELEMINATES CROSS-PRODUCT TERM
C     IN DIGITAL PERFORMANCE INDEX
      IOP(3)=1
      CALL EQUATE(ATIL,NATIL,AHAT,NAHAT)
      CALL EQUATE(QTIL,NQTIL,QHAT,NQHAT)
      CALL PREFIL(AHAT,NAHAT,BTIL,NBTIL,QHAT,NQHAT,WTIL,NWTIL,RTIL,NRTIL
     1,FTIL,NFTIL,IOP,DUMMY)
      CALL PRNT(AHAT,NAHAT,4HAHAT,1)
      CALL PRNT(QHAT,NQHAT,4HQHAT,1)
      CALL PRNT(FTIL,NFTIL,4HFTIL,1)
C
C     SOLVE FOR F HAT
      IDENT= .TRUE.
      DISC = .TRUE.
      NEWT = .TRUE.
      STABLE = .FALSE.
      FNULL = .TRUE.
      ALPHA = .9
      IOP(1) = 1
      IOP(2) = 0
      IOP(3) = 0
      IOP(4) = 1
      IOP(5) = 1
      CALL ASMREG(AHAT,NAHAT,BTIL,NBTIL,H,NH,QHAT,NQHAT,RTIL,NRTIL,FHAT
     1,NFHAT,P,NP,IDENT,DISC,NEWT,STABLE,FNULL,ALPHA,IOP,DUMMY)
      CALL ADD(FTIL,NFTIL,FHAT,NFHAT,F,NF)
C
C     OUTPUT F AND F HAT GAINS
      CALL LNCNT(100)
      PRINT 100
  100 FORMAT('       FOR THE ORIGINAL SAMPLED-DATA PROBLEM')
      CALL PRNT(FHAT,NFHAT,4HFHAT,1)
      CALL PRNT(F,NF,4HF   ,1)
C
      STOP
      END
      OUTPUT FOR SAMPLED-DATA REGULATOR PROBLEM
 A         4   4
      -2.6       .25      -38.       0.0
     -.075      -.27       4.4       0.0
      .078      -.99      -.23      .052
        1.      .078       0.0       0.0
 B         4   2
       17.        7.
       .82      -3.2
       0.0      .046
       0.0       0.0
 Q         4   4
        1.       0.0       0.0       0.0
       0.0        1.       0.0       0.0
       0.0       0.0        1.       0.0
       0.0       0.0       0.0        1.
 R         2   2
        1.       0.0
       0.0        1.
